//
//  ZhouViewController.m
//  Yu01
//
//  Created by 蒋松涵 on 16/8/25.
//  Copyright © 2016年 蒋松涵. All rights reserved.
//

#import "ZhouViewController.h"
#import "schoolTimetableViewController.h"
#import "cyhCalenbarview.h"
#import "monthCalenbarview.h"
#import "zySheetPickerView.h"
#import "XuKeViewController.h"

@interface ZhouViewController ()<UITableViewDataSource,UITableViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate,getdataString,monthdataString>

@property(nonatomic,strong)UITableView * tableView;

@property (nonatomic , strong)cyhCalenbarview * cyhcalenbar;
@property (nonatomic , strong)monthCalenbarview * monthCalenbar;
@property (nonatomic , copy)NSString * daydatestr;

@property (nonatomic, strong)NSString * NSStringLabel;

@end

@implementation ZhouViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.title = @"周课表";
    UIBarButtonItem * rightBtn = [[UIBarButtonItem alloc]initWithTitle:@"周" style:UIBarButtonItemStylePlain target:self action:@selector(rightBtn)];
    self.navigationItem.rightBarButtonItem = rightBtn;
    
    [self tableview];
    [self collectionview];
    [self riLi];
}
#pragma mark - 日历
-(void)riLi
{
    //初始化，如果日历小于120.0的高度将默认为120.0高度
    _cyhcalenbar = [[cyhCalenbarview alloc] initD_calenbarframe:CGRectMake(80, 64, ScreenWidth, 80)];
    _cyhcalenbar.daydelegate = self;
    //注册使用
    [_cyhcalenbar daycalenbarviewNSdate];
    
    CGFloat R_1 = 241.0/255.0;
    CGFloat G_1 = 241.0/255.0;
    CGFloat B_1 = 241.0/255.0;
    //日历背景颜色
    _cyhcalenbar.calenbarBGcolor = [UIColor colorWithRed:R_1 green:G_1 blue:B_1 alpha:1];
    
    CGFloat R_2 = 241.0/255.0;
    CGFloat G_2 = 241.0/255.0;
    CGFloat B_2 = 241.0/255.0;
    //星期排列背景颜色
    _cyhcalenbar.WeekBGcolor = [UIColor colorWithRed:R_2 green:G_2 blue:B_2 alpha:1];
    
    CGFloat R_3 = 235.0/255.0;
    CGFloat G_3 = 104.0/255.0;
    CGFloat B_3 = 89.0/255.0;
    //当天日期圆点颜色
    _cyhcalenbar.todayNumBGcolor = [UIColor colorWithRed:R_3 green:G_3 blue:B_3 alpha:1];
    
    CGFloat R_4 = 52.0/255.0;
    CGFloat G_4 = 141.0/255.0;
    CGFloat B_4 = 170.0/255.0;
    //被选中的日期圆点颜色
    _cyhcalenbar.SelecNumBGcolor = [UIColor colorWithRed:R_4 green:G_4 blue:B_4 alpha:1];
    
    CGFloat R_5 = 235.0/255.0;
    CGFloat G_5 = 104.0/255.0;
    CGFloat B_5 = 89.0/255.0;
    //当天日期数字颜色
    _cyhcalenbar.todaytextColor = [UIColor colorWithRed:R_5 green:G_5 blue:B_5 alpha:1];
    
    [self.view addSubview:_cyhcalenbar.daycalenbarview];
}

- (void)getDatestring:(NSString *)datestring
{
    _daydatestr = datestring;
    NSLog(@"回调回来的日期:%@",_daydatestr);
    
}

#pragma mark - CollectionView
-(void)collectionview
{
    // 流水布局
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
    // 设置cell的尺寸
    CGFloat screecW = [UIScreen mainScreen].bounds.size.width;
    //    layout.itemSize = CGSizeMake(50, 50);
    
    //每个cell的间距
    CGFloat minimum = 1;
    //一行cell 的个数
    CGFloat count = 9;
    //每一行的上下距离
    CGFloat minimum2 = 1;
    //每个cell的宽
    CGFloat cellW = (screecW  - minimum *count - minimum)/count ;
    //每个cell的高
    CGFloat cellH = cellW;
    layout.itemSize = CGSizeMake(cellW, cellH);
    
    // 设置每一行的间距
    layout.minimumLineSpacing = minimum2;
    
    // 设置每个cell的间距
    layout.minimumInteritemSpacing = minimum;
    UICollectionView *collectionView =[[UICollectionView alloc]initWithFrame:CGRectMake(80, 125, ScreenWidth - 80, ScreenHeight - 125) collectionViewLayout:layout];
    collectionView.backgroundColor =[UIColor whiteColor];
    collectionView.delegate =self;
    collectionView.dataSource =self;
    [self.view addSubview:collectionView];
    
    [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
}

#pragma mark - UICollectionView数据源
// 返回有多少个cell
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 56;
}

// 返回每个cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    UICollectionViewCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
//    UIColor * color = [UIColor greenColor];
//    cell.backgroundColor = color;

    UIColor *color =[UIColor colorWithRed:223/255.0 green:242/255.0 blue:249/255.0 alpha:1];
    cell.backgroundColor =color;
    
    if (indexPath.row == 0 || indexPath.row == 7)
    {
        UIView * vi_s = [[UIView alloc]initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height + cell.frame.size.height)];
        vi_s.backgroundColor = [UIColor colorWithRed:140/255.0 green:191/255.0 blue:50/255.0 alpha:1];
        [cell.contentView addSubview:vi_s];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 20, cell.frame.size.height)];
//        label.text = @"平\n面\n构\n成\n 2-308";
        label.numberOfLines = [label.text length];
        label.textColor = [UIColor whiteColor];
        [vi_s addSubview:label];
    }
    else if (indexPath.row == 2 || indexPath.row == 9)
    {
        UIView * vi_s = [[UIView alloc]initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height + cell.frame.size.height)];
        vi_s.backgroundColor = [UIColor colorWithRed:123/255.0 green:157/255.0 blue:226/255.0 alpha:1];
        [cell.contentView addSubview:vi_s];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 20, cell.frame.size.height)];
//        label.text = @"平\n面\n构\n成\n 2-308";
        label.numberOfLines = [label.text length];
        label.textColor = [UIColor whiteColor];
        [vi_s addSubview:label];
    }
    else if (indexPath.row ==4  || indexPath.row == 11)
    {
        UIView * vi_s = [[UIView alloc]initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height + cell.frame.size.height)];
        vi_s.backgroundColor = [UIColor colorWithRed:103/255.0 green:179/255.0 blue:156/255.0 alpha:1];
        [cell.contentView addSubview:vi_s];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 20, cell.frame.size.height)];
        //        label.text = @"平\n面\n构\n成\n 2-308";
        label.numberOfLines = [label.text length];
        label.textColor = [UIColor whiteColor];
        [vi_s addSubview:label];
    }
    else if (indexPath.row == 15 || indexPath.row == 22)
    {
        UIView * vi_s = [[UIView alloc]initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height + cell.frame.size.height)];
        vi_s.backgroundColor = [UIColor colorWithRed:81/255.0 green:182/255.0 blue:223/255.0 alpha:1];
        [cell.contentView addSubview:vi_s];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 20, cell.frame.size.height)];
        //        label.text = @"平\n面\n构\n成\n 2-308";
        label.numberOfLines = [label.text length];
        label.textColor = [UIColor whiteColor];
        [vi_s addSubview:label];
    }
    else if (indexPath.row == 17 || indexPath.row == 24)
    {
        UIView * vi_s = [[UIView alloc]initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height + cell.frame.size.height)];
        vi_s.backgroundColor = [UIColor colorWithRed:245/255.0 green:93/255.0 blue:129/255.0 alpha:1];
        [cell.contentView addSubview:vi_s];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 20, cell.frame.size.height)];
        //        label.text = @"平\n面\n构\n成\n 2-308";
        label.numberOfLines = [label.text length];
        label.textColor = [UIColor whiteColor];
        [vi_s addSubview:label];
    }
    else if (indexPath.row == 28 || indexPath.row == 35)
    {
        UIView * vi_s = [[UIView alloc]initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height + cell.frame.size.height)];
        vi_s.backgroundColor = [UIColor colorWithRed:123/255.0 green:157/255.0 blue:226/255.0 alpha:1];
        [cell.contentView addSubview:vi_s];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 20, cell.frame.size.height)];
        //        label.text = @"平\n面\n构\n成\n 2-308";
        label.numberOfLines = [label.text length];
        label.textColor = [UIColor whiteColor];
        [vi_s addSubview:label];
    }
    else if (indexPath.row == 31 || indexPath.row == 38)
    {
        UIView * vi_s = [[UIView alloc]initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height + cell.frame.size.height)];
        vi_s.backgroundColor = [UIColor colorWithRed:103/255.0 green:179/255.0 blue:156/255.0 alpha:1];
        [cell.contentView addSubview:vi_s];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 20, cell.frame.size.height)];
        //        label.text = @"平\n面\n构\n成\n 2-308";
        label.numberOfLines = [label.text length];
        label.textColor = [UIColor whiteColor];
        [vi_s addSubview:label];
    }
    else if (indexPath.row == 32 || indexPath.row == 39)
    {
        UIView * vi_s = [[UIView alloc]initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height + cell.frame.size.height)];
        vi_s.backgroundColor = [UIColor colorWithRed:81/255.0 green:182/255.0 blue:223/255.0 alpha:1];
        [cell.contentView addSubview:vi_s];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 20, cell.frame.size.height)];
//                label.text = @"平\n面\n构\n成\n 2-308";
        label.numberOfLines = [label.text length];
        label.textColor = [UIColor whiteColor];
        [vi_s addSubview:label];
    }
    else if (indexPath.row == 43 || indexPath.row == 50)
    {
        UIView * vi_s = [[UIView alloc]initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)];
        vi_s.backgroundColor = [UIColor colorWithRed:245/255.0 green:93/255.0 blue:129/255.0 alpha:1];
        [cell.contentView addSubview:vi_s];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 20, cell.frame.size.height)];
        //        label.text = @"平\n面\n构\n成\n 2-308";
        label.numberOfLines = [label.text length];
        label.textColor = [UIColor whiteColor];
        [vi_s addSubview:label];
    }
    else if (indexPath.row == 44 || indexPath.row == 51)
    {
        UIView * vi_s = [[UIView alloc]initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)];
        vi_s.backgroundColor = [UIColor colorWithRed:140/255.0 green:191/255.0 blue:50/255.0 alpha:1];
        [cell.contentView addSubview:vi_s];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 20, cell.frame.size.height)];
//        label.text = @"平\n面\n构\n成\n 2-308";
        label.numberOfLines = [label.text length];
        label.textColor = [UIColor whiteColor];
        [vi_s addSubview:label];
    }
    else if (indexPath.row == 46 || indexPath.row == 53)
    {
        UIView * vi_s = [[UIView alloc]initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)];
        vi_s.backgroundColor = [UIColor colorWithRed:54/255.0 green:152/255.0 blue:218/255.0 alpha:1];
        [cell.contentView addSubview:vi_s];
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 20, cell.frame.size.height)];
//        label.text = @"平\n面\n构\n成\n 2-308";
        label.numberOfLines = [label.text length];
        label.textColor = [UIColor whiteColor];
        [vi_s addSubview:label];
    }
    
    return cell;
}

#pragma mark - tableview
-(void)tableview
{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 80, ScreenHeight) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
//    self.tableView.rowHeight = 80;
    //禁止滑动
    self.tableView.scrollEnabled = NO;
    //去掉多余的表（线）
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.view addSubview:self.tableView];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 9;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    if (indexPath.row == 0)
    {
        UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
        button.frame = CGRectMake(30,40, 20, 20);
        [button setBackgroundImage:[UIImage imageNamed:@"下拉按钮图标-07"] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(buttonWithTypes) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:button];
        
//        cell.textLabel.text = self.NSStringLabel;
        
        cell.backgroundColor = [UIColor colorWithRed:236/255.0 green:237/255.0 blue:238/255.0 alpha:1];
        
        UIButton * button1 = [UIButton buttonWithType:UIButtonTypeSystem];
        button1.frame = CGRectMake(30,10, 20, 20);
        [button1 setBackgroundImage:[UIImage imageNamed:@"下拉按钮图标-08"] forState:UIControlStateNormal];
        [button1 addTarget:self action:@selector(buttonWithTypes) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:button1];
        
        //        cell.textLabel.text = self.NSStringLabel;
        
        
    }
    else if (indexPath.row == 1)
    {
        cell.textLabel.text = @"1";
        cell.textLabel.font = [UIFont systemFontOfSize:15];
    }
    else if (indexPath.row == 2)
    {
        cell.textLabel.text = @"2";
        cell.textLabel.font = [UIFont systemFontOfSize:15];
    }
    else if (indexPath.row == 3)
    {
        cell.textLabel.text = @"3";
        cell.textLabel.font = [UIFont systemFontOfSize:15];
    }
    else if (indexPath.row == 4)
    {
        cell.textLabel.text = @"4";
        cell.textLabel.font = [UIFont systemFontOfSize:15];
    }
    else if (indexPath.row == 5)
    {
        cell.textLabel.text = @"5";
        cell.textLabel.font = [UIFont systemFontOfSize:15];
    }
    else if (indexPath.row == 6)
    {
        cell.textLabel.text = @"6";
        cell.textLabel.font = [UIFont systemFontOfSize:15];
    }
    else if (indexPath.row == 7)
    {
        cell.textLabel.text = @"7";
        cell.textLabel.font = [UIFont systemFontOfSize:15];
    }
    else
    {
        cell.textLabel.text = @"8";
        cell.textLabel.font = [UIFont systemFontOfSize:15];
    }

    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        return 60;
    }
    else if (indexPath.row == 1)
    {
        return 45;
    }
    else if (indexPath.row == 2)
    {
        return 47;
    }
    else if (indexPath.row == 3)
    {
        return 45;
    }
    else if (indexPath.row == 4)
    {
        return 46;
    }
    else if (indexPath.row == 5)
    {
        return 46;
    }
    else if (indexPath.row == 6)
    {
        return 46;
    }
    else if (indexPath.row == 7)
    {
        return 46;
    }
    else
    {
        return 46;
    }

}
-(void)rightBtn
{
    self.hidesBottomBarWhenPushed = YES;
    XuKeViewController * XuKeVC = [[XuKeViewController alloc]init];
    [self.navigationController pushViewController:XuKeVC animated:YES];
}

-(void)buttonWithTypes
{
    NSArray * str  = @[@"第1周",@"第2周",@"第3周",@"第4周",@"第5周",@"第6周",@"第7周",@"第8周",@"第9周",@"第10周"];
    zySheetPickerView *pickerView = [zySheetPickerView ZYSheetStringPickerWithTitle:str andHeadTitle:@"选择月份" Andcall:^(zySheetPickerView *pickerView, NSString *choiceString) {
        
        self.NSStringLabel = choiceString;
        
        [pickerView dismissPicker];
    }];
    [pickerView show];
    
    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
